package firstdatatest;

import java.math.BigDecimal;
import java.rmi.RemoteException;
import java.util.Properties;
import java.util.Set;

import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.Amount;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.Card;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.CardNumber_type1;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.ChargeTotal_type1;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.CreditCardData;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.CreditCardDataChoice_type0;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.CreditCardDataSequence_type0;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.CreditCardTxType;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.ExpMonth_type1;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.ExpYear_type1;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.FDGGWSApiOrderRequest;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.FDGGWSApiOrderResponse;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.Payment;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.Payment_type0;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.Transaction;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.TransactionChoice_type0;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.TransactionSequence_type0;
import net.linkpt.secure.fdggwsapi.schemas_us.fdggwsapi.FDGGWSApiOrderServiceStub.Type_type1;

import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;

public class FDGGWSAxisClient { 
	 
	public static void main (String args[]) { 
		
		String URL_LIVE="https://ws.firstdataglobalgateway.com/fdggwsapi/services";
	    String URL_SANDBOX="https://ws.merchanttest.firstdataglobalgateway.com:443/fdggwsapi/services";
	 
		//the keystore file and password used on the next 2 lines are found within the store CERT files archive  
		//which may be download via Virtual Terminal (under Support - Download Center) 
		
	    //boolean isSandbox=true;
		boolean isSandbox=false;
		
		Properties p=System.getProperties();
		Set keys=p.keySet();
		for(Object obj : keys){
			System.out.println(obj+"="+p.getProperty((String)obj));
		}
		
		if(isSandbox){
			System.setProperty("javax.net.ssl.keyStore","D:\\Remote_Gateways\\First Data\\FDGGWS_Certificate_WS1909106641._.1\\WS1909106641._.1.ks"); 
			System.setProperty("javax.net.ssl.keyStorePassword","RScAwJ4RwJ");
		}else{
			System.setProperty("javax.net.ssl.keyStore","D:\\Remote_Gateways\\First Data\\FDGGWS_Certificate_WS1001297615._.1\\WS1001297615._.1.ks"); 
			//System.setProperty("javax.net.ssl.keyStorePassword","iY9VLxU2uw");
			System.setProperty("javax.net.ssl.keyStorePassword","xiY9VLxU2uw");
		}
		
		System.setProperty("javax.net.ssl.keyStore","");
		System.setProperty("javax.net.ssl.keyStorePassword","xx");
		
		p=System.getProperties();
		keys=p.keySet();
		System.out.println("----------------------------------------------------");
		for(Object obj : keys){
			System.out.println(obj+"="+p.getProperty((String)obj));
		}
		
		HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); 
		auth.setPreemptiveAuthentication(true); 
		     
		//the following username and password values come from the WS<storename>._.1.auth.txt file 
		//which is found inside the store CERT files archive that may be download via Virtual Terminal (under Support - Download Center) 
		if(isSandbox){
			auth.setUsername("WS1909106641._.1"); 
			auth.setPassword("xx"); 
		}else{
			auth.setUsername("WS1001297615._.1"); 
			auth.setPassword("xx"); 
		}
		
		     
		FDGGWSApiOrderServiceStub fdggWsStub = null;
		try {
			if(isSandbox){
				fdggWsStub = new FDGGWSApiOrderServiceStub(URL_SANDBOX);
			}else{
				fdggWsStub = new FDGGWSApiOrderServiceStub(URL_LIVE);
			}
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		Options options = fdggWsStub._getServiceClient().getOptions(); 
		options.setProperty(HTTPConstants.AUTHENTICATE, auth); 
		     
		Type_type1 sale_type = Type_type1.value6; 
		 
		CreditCardTxType creditCardTxType = new CreditCardTxType(); 
		creditCardTxType.setType(sale_type); 
		   
		CardNumber_type1 cardNumber_type1 = new CardNumber_type1(); 
		cardNumber_type1.setCardNumber_type0("4012000033330026"); 
		 
		ExpMonth_type1 expMonth_type1 = new ExpMonth_type1(); 
		expMonth_type1.setExpMonth_type0("12"); 
		   
		ExpYear_type1 expYear_type1 = new ExpYear_type1(); 
		expYear_type1.setExpYear_type0("12"); 
		   
		Card card = new Card(); 
		card.setCardNumber(cardNumber_type1); 
		card.setExpMonth(expMonth_type1); 
		card.setExpYear(expYear_type1); 
	 
		 
		CreditCardDataSequence_type0 creditCardDataSequence_type0 = new 
		CreditCardDataSequence_type0(); 
		 
		creditCardDataSequence_type0.setCard(card); 
		   
		CreditCardDataChoice_type0 dataChoice = new CreditCardDataChoice_type0(); 
		dataChoice.setCreditCardDataSequence_type0(creditCardDataSequence_type0); 
		   
		CreditCardData creditCardData = new CreditCardData(); 
		creditCardData.setCreditCardDataChoice_type0(dataChoice); 
		   
		BigDecimal bigDecimal = new BigDecimal("11"); 
		   
		ChargeTotal_type1 chargeTotal_type1 = new ChargeTotal_type1(); 
		chargeTotal_type1.setChargeTotal_type0(bigDecimal); 
		     
		Amount amount = new Amount(); 
		amount.setChargeTotal(chargeTotal_type1); 
		   
		Payment_type0 payment_type0 = new Payment_type0(); 
		payment_type0.setAmount(amount); 
		   
		Payment payment = new Payment(); 
		payment.setPayment(payment_type0); 
		   
		TransactionSequence_type0 transactionSequence_type0 = new 
		TransactionSequence_type0(); 
		 
		transactionSequence_type0.setCreditCardTxType(creditCardTxType); 
		transactionSequence_type0.setCreditCardData(creditCardData); 
		   
		TransactionChoice_type0 transactionChoice_type0= new 
		TransactionChoice_type0();  
		 
		transactionChoice_type0.setTransactionSequence_type0(transactionSequence_type0); 
		       
		Transaction t = new Transaction(); 
		t.setTransactionChoice_type0(transactionChoice_type0); 
		t.setPayment(payment_type0); 
		 
		FDGGWSApiOrderRequest fdggwsApiOrderRequest = new FDGGWSApiOrderRequest(); 
		   
		fdggwsApiOrderRequest.setTransaction(t); 
		   
		FDGGWSApiOrderResponse response = null;
		try {
			response = fdggWsStub.fDGGWSApiOrder(fdggwsApiOrderRequest);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		   
		System.out.println("The Transaction Result is "+response.getTransactionResult()); 
		 
		System.out.println("The Order ID is "+response.getOrderId()); 
		 

	} 
}